using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class EnergyTime : IQuantity
	{
		private double value;

		private EnergyTime(double value)
		{
			this.value = value;
		}

		public static EnergyTime FromUnit(IUnitSystem system, double value)
		{
			return new EnergyTime(value / (system.EnergyScaling * system.TimeScaling));
		}

		public static EnergyTime FromElectronVoltSecond(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		public static EnergyTime FromJouleSecond(double value)
		{
			return FromUnit(UnitSystem.InternationalSystem, value);
		}
		
		public double ToUnit(IUnitSystem system)
		{
			return value * system.EnergyScaling * system.TimeScaling;
		}

		public double ToElectronVoltSecond()
		{
			return ToUnit(UnitSystem.AtomicSystem);
		}

		public double ToJouleSecond()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}
		
		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} eV*s = {1} J*s", ToElectronVoltSecond(), ToJouleSecond());
			}
		}
	}
}
